/**
 * Created by ptt on 2016/5/27/0027.
 */

var map;
var szvector;
var Message_bone = $({});
//GISt基础地图
var mapURL = {
        gistBaseMapurl: "http://gist.sz95000.com/tiles/wmts",
        //TGISWMS服务地址
        tgisWmsUrl:"http://gist.sz95000.com/server/gist/wms",
        //深圳路网WFS服务
        tgisRoadWfsUrl:"http://218.17.162.92:9898/geoserver/szroad/wfs",
       //项目地图信息
        projectWfs:"http://218.17.162.92:9898/geoserver/ssjc_pro/wfs",
        //深圳规划信息
        szghWmsUrl:"http://218.17.162.92:9898/geoserver/szgh/wms",
        //养护标段
        szyhbdWmsUrl:"http://218.17.162.92:9898/geoserver/yhbd/wms",
        //路网
        szRoadurl: "http://218.17.162.92:6080/arcgis/rest/services/sz/lw/MapServer",
        //pci
        szPciurl: "http://218.17.162.92:6080/arcgis/rest/services/sz/pci/MapServer",
        //病害
        szRoadbh: "http://218.17.162.92:6080/arcgis/rest/services/sz/bh/MapServer",
        //规划
        szRoadGh: "http://218.17.162.92:6080/arcgis/rest/services/sz/gh2/MapServer",
        //深圳背景地图
        szbasemap:"http://218.17.162.92:6080/arcgis/rest/services/sz/basemap/MapServer",
        //深圳区划
       szDistrictsUrl:"http://218.17.162.92:9898/geoserver/szdistricts/wms",
    };
/*var districkcentre = {
 "440301": [113.974, 22.556],
 "440302": [114.203, 22.588],
 "440303": [113.808, 22.699],
 "440304": [114.275, 22.740],
 "440305": [113.926, 22.766],
 "440306": [114.357, 22.691],
 "440307": [114.030, 22.687],
 "440308": [114.550, 22.520]
 };*/
var districkcentre = {
    "440303": [114.143, 22.558],//罗湖
    "440304": [114.045, 22.531],//福田
    "440305": [113.948, 22.545],//南山
    "440306": [113.870, 22.627],//宝安
    "440307": [114.211, 22.655],//龙岗
    "440308": [114.258, 22.590],//盐田
    "440309": [113.936, 22.783],//光明
    "440310": [114.363, 22.685],//坪山
    "440311": [114.032, 22.688],//龙华
    "440312": [114.479, 22.599],//大鹏
};
var mapp = {
    "市政道路": "102",
    "公路": "101",
    "道路长度": "length",
    "道路数量": "amount",
    "道路面积": "acreage",
    "验收率":"rateDA",
    "巡查达标率":"rateOfInspection ",
    "主动发现率":"rateFind",
    "处置完成率":"rateDeal"
};
var chartsType = {
    "饼状": "pie",
    "柱状": "bar",
    "线状": "line"
};
var queryConfig={
    queryRoad:{
        url:mapURL.tgisRoadWfsUrl,
        layers:["ptroad"],
        featureNS:"http://192.168.0.50:9898/szroad",
        featurePrefix:"szroad",
        queryFieldName:"hb_code",
        classFieldName:"class",
        nameFieldName:"name"
    },
    queryProject:{
        url:mapURL.projectWfs,
        layers:["ssjc_pro_line","ssjc_pro_point","ssjc_pro_polygon"],
        featureNS:"http://192.168.0.6:9898/ssjc_pro",
        featurePrefix:"ssjc_pro",
        queryFieldName:"projectid",
        classFieldName:"projecttype",
        nameFieldName:"projectname"
    },
    queryBiaoDuan:{
        url:mapURL.szyhbdWmsUrl,
        layers:"yhbd:szyhbd"
    },
    queryDistricts:{
        url:mapURL.szDistrictsUrl,
        layers:"szdistricts:szdistricts_layergroup"
    }
};
var porjectConfig={
    //施工项目
    constructproject:{
        detailUrl:"/ssjc/mp/view/project!view.action?id=",
    },
    //规划项目
    planproject:{
        detailUrl:"/ssjc/pl/view/planpreparepoj!oview.action?id=",
    },
    //大中修项目
    repairproject:{
        detailUrl:"/ssjc/yh/view/maintenance!view.action?id=",
    },
    //前期项目
    earlierproject:{
        detailUrl:"/ssjc/pre/view/preparepoj!view.action?id=",
    },
    projectInfo:{
        detailUrl:"/ssjc/tl/projects!findProjectInfoById.action?",
    }
};
var m_TempLayer;
var m_StaticLayers;
function m_reMoveLayerAndolay()
{
    var olay = $("#overlay").data("query");
    olay && olay.setPosition([9999, 9999]);
    //移除图层
    if(m_TempLayer&&map)
    {
        map.removeLayer(m_TempLayer);
        for(var i=0;i< map.getLayers().getArray().length;i++)
        {
            var mapLayer=map.getLayers().getArray()[i];
            if(mapLayer.getKeys().indexOf("layerName")>0){
                map.removeLayer(mapLayer);
            }
        }
    };
    //移除统计图层
    if(m_StaticLayers&&map)
    {
        for(var i=0;i<m_StaticLayers.length;i++) {
            map.removeOverlay(m_StaticLayers[i]);
        }
    };
    //移除选择操作事件
    if(map)
    {
        if(map.getInteractions().getLength()>0){
            for(var i=0;i<map.getInteractions().getLength();i++)
            {
                if(map.getInteractions().getArray()[i] instanceof ol.interaction.Select) {
                    map.removeInteraction(map.getInteractions().getArray()[i]);
                }
            }
        }
    }
    //移除图例
    Message_bone.trigger("legendHide");
};

var curingData={
    disease:{
        dataQuery:{
            url:"/ssjc/tl/projects!findDDGeoJsonById.action?",
            queryAllurl:"/ssjc/tl/projects!findDDGeoJsonByRId.action?",
            queryField:"id",
            detailUrl:appConfig.repairAddress+"/inspection/damagedisease!getDetail.action?caseNo=",
        }
    },
    maintain:{
        dataQuery:{
            url:"/ssjc/tl/projects!findFTGeoJsonById.action?",
            queryAllurl:"/ssjc/tl/projects!findFTGeoJsonByRId.action?",
            queryField:"id",
            detailUrl:appConfig.repairAddress+"/fit/roadfit!info.action?id="
        }
    },
    modify:{
        dataQuery:{
            url:"/ssjc/tl/projects!findRRGeoJsonById.action?",
            queryAllurl:"/ssjc/tl/projects!findRRGeoJsonByRId.action?",
            queryField:"id",
            sbUrl:appConfig.repairAddress+"/rep/roadrepairapply!input.action?hd=0&type=1&num=0&roadRepairID=",
            ysUrl:appConfig.repairAddress+"/rep/roadrepairaccept!getRepairAccept.action?flag=1&num=1&roadRepairID=",
        }
    },
    checkpoint:{
        dataQuery:{
            xqUrl:"/ssjc/taglib/urbanroadinfo!map.action?id=",
        }
    },
    property:{
    	dataQuery:{
            pdfUrl:"/ssjc/doc/archivecatalog!openFile.action?catalogNum=",
        }
    }
};

$(function () {
    require(["../scripts/gis/gis/loadMap.js",
        "../scripts/component/navigation/listener.js",
        "../scripts/component/popup/listener.js",
        "../scripts/component/slicePage/listener.js",
        "../scripts/component/searchbox/listener.js",
        "../scripts/component/searchbox/thematicMap.js",
        "../scripts/component/information/listener.js",
        "../scripts/component/detail_page/listener.js",
        "../scripts/component/legend/listener.js",
        "../scripts/component/suggest/listener.js",
        "../scripts/component/life/listener.js",
        "../scripts/component/life/message.js"
        //"../scripts/component/scroll_select/listener.js"
        //"../scripts/component/searchbox/listener.js",
        //"../scripts/component/popup/listener.js",
        //"../scripts/component/navigation/listener.js",
        //"../scripts/component/statistics/chart.js"
    ], function (map, nav, popup, spage) {
        nav = nav.navigationController;
        $("#mapContain").on("mousedown", function (e) {
            var parents = $(e.target).parents();
            for (var i = 0, elem; elem = parents[i++]; ) {
                if (elem === this) break;
            }
            elem === this && !$("#popup").hasClass("hidden") && nav.trigger("divStat", "click");
        //
        });
    });
});

